﻿namespace SpecUnit.Samples.Atm
{
    public class AutomatedTellerMachine
    {
        public AutomatedTellerMachine(int availableCash)
        {
            AvailableCash = availableCash;
        }

        public int AvailableCash
        {
            get; private set;
        }

        public int DispenseValue
        {
            get; set;
        }

        public bool CardIsRetained
        {
            get; private set;
        }

        public DisplayMessage Message
        {
            get; private set;
        }

        public void RequestMoney(Card card, int request)
        {
            if (!card.IsEnabled)
            {
                CardIsRetained = true;
                Message = DisplayMessage.CardIsRetained;
                return;
            }

            if (card.AccountBalance < request || AvailableCash < request)
            {
                Message = DisplayMessage.InsufficientFunds;
                return;
            }

            DispenseValue = request;

            AvailableCash -= request;
            card.AccountBalance -= request;
        }

    }
}
